package service;

import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class JDBCConnect {
    public static Connection getConnection() {
        Connection connection = null;
        Properties properties = new Properties();
        try {
            InputStream in = JDBCConnect.class.getClassLoader().getResourceAsStream("jdbc.properties");
            properties.load(in);

            String driver = properties.getProperty("driver");
            String url = properties.getProperty("jdbcUrl");
            String user = properties.getProperty("user");
            String password = properties.getProperty("password");

            Class.forName(driver);

            connection = DriverManager.getConnection(url, user, password);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }
}
